//
//  SASelectImageCell.m
//  saasRetail
//
//  Created by mac on 2022/10/23.
//

#import "SASelectImageCell.h"

@interface SASelectImageCell()

@property (weak, nonatomic) UIImageView *iconImageView;
@property (weak, nonatomic) UIView *mongoliaView;
@property (weak, nonatomic) UIButton *selectedImageBtn;

@end

@implementation SASelectImageCell
-(instancetype)initWithFrame:(CGRect)frame
{
    if(self  =[super initWithFrame:frame])
    {
        
        [self setUpsUbViews];
    }
    return self;
}

-(void)setUpsUbViews
{
    self.contentView.backgroundColor = [UIColor clearColor];
    self.contentView.userInteractionEnabled = YES;
      self.contentView.layer.cornerRadius = kScaleNum(5);
      self.contentView.layer.masksToBounds = YES;
    
    UIView *mongoliaView = [[UIView alloc] init];
    mongoliaView.userInteractionEnabled = YES;
    mongoliaView.layer.cornerRadius = kScaleNum(5);
    mongoliaView.layer.masksToBounds = YES;
    mongoliaView.backgroundColor = kColor(255, 255, 255, 1);
    [self.contentView addSubview:mongoliaView];
    self.mongoliaView = mongoliaView;
    [mongoliaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(kScaleNum(0)));
        make.top.equalTo(@(kScaleNum(0)));
        make.width.mas_equalTo(kScaleNum(60));
        make.height.mas_equalTo(kScaleNum(75));
    }];
    
    UIImageView *iconImageView = [[UIImageView alloc] init];
    iconImageView.contentMode = UIViewContentModeScaleAspectFit;
    iconImageView.userInteractionEnabled = YES;
    iconImageView.clipsToBounds = YES;
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(kScaleNum(0)));
        make.top.equalTo(@(kScaleNum(0)));
        make.width.mas_equalTo(kScaleNum(60));
        make.height.mas_equalTo(kScaleNum(75));
    }];
    UIButton * deleteImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    deleteImageBtn.frame = CGRectMake(kScaleNum(35), kScaleNum(4), kScaleNum(20), kScaleNum(20));
    [deleteImageBtn setBackgroundImage:[UIImage imageNamed:@"product_choose_delete_btn"] forState:UIControlStateNormal];
    [deleteImageBtn addTarget:self action:@selector(deleteImageBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [iconImageView addSubview:deleteImageBtn];
    
    UIButton *selectedImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    selectedImageBtn.frame = CGRectMake(kScaleNum(0), kScaleNum(100), kScaleNum(100), kScaleNum(25));
    [selectedImageBtn setImage:[UIImage imageNamed:@"product_choose_image_selected"] forState:UIControlStateNormal];
    [selectedImageBtn setImage:[UIImage imageNamed:@"product_choose_image_selected_s"] forState:UIControlStateSelected];
    [selectedImageBtn setTitle:@"  设置封面" forState:UIControlStateNormal];
    [selectedImageBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    selectedImageBtn.titleLabel.font = kBFont(12);
    selectedImageBtn.userInteractionEnabled = NO;
    selectedImageBtn.backgroundColor = kColor(0, 0, 0, 0.6);
//    [iconImageView addSubview:selectedImageBtn];
    self.selectedImageBtn = selectedImageBtn;
}

-(void)deleteImageBtnClick
{
    if (self.deleteImageBlock) {
        self.deleteImageBlock();
    }
}

-(void)loadData:(SAProductChooseImageModel *)model
{
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.url]];
   
    if (model.isSelecd == YES) {
        self.selectedImageBtn.selected = YES;
    }else
    {
        self.selectedImageBtn.selected = NO;
    }
}

@end
